<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="wrap">
    <button class="btn">删除</button>
    <div class="list">
      <li class="first">01</li>
      <li>02</li>
      <li class="mid">03</li>
      <li>04</li>
      <li>05</li>
      <li class="last">06</li>
      <!-- <li>07</li> -->
    </div>
  </div>
</body>
<script>
  // 节点的删除
  // 1. 自删    Element.remove()   => 返回的undefined

  // 2. 父删    parent.removeChild(node)  => 父元素统筹



  var list = document.getElementsByClassName("list")[0];
  var mid = document.getElementsByClassName("mid")[0];
  var btn = document.getElementsByClassName("btn")[0];


  // 点击新增按钮 创建li => 放到list中
  btn.onclick = function () {
    // 自删 
    // var result = mid.remove();  // 返回值undefined
    // console.log(result);

    // 父删   => 重复删除会报错(The node to be removed is not a child of this node.)
    if (mid) {//mid存在 
      list.removeChild(mid);
      mid = null;  //清除mid
    }
  }




</script>

</html>